package com.uenpay.im.invokeitems;

import com.qiyunxin.android.http.listener.OnHttpRequestTextListener;
import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.net.HttpRequestAsyncTaskQueue;
import com.qiyunxin.android.http.net.HttpTextAsyncTask;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @date 2016-5-17 下午7:59:57
 * @version 1.0
 * @function 网络请求基本请求
 * 
 */
public class HttpRequestHandle {

	/**
	 * 返回结果
	 * 
	 * @author　SL
	 * 
	 */
	public interface IRequestResultListener {
		/**
		 * 返回数据
		 * 
		 * @param resultObject
		 * @param isCache
		 * @param failReason
		 */
		public abstract void onResult(Object resultObject, boolean isCache,
									  String failReason);
	}

	/**
	 * 请求网络
	 * 
	 * @param item
	 * @param HttpRequestType
	 * @param requestResultListener
	 */
	public static void onBaseRequest(HttpInvokeItem item, int HttpRequestType,
			final IRequestResultListener requestResultListener) {
		HttpRequestAsyncTaskQueue.getInstance().AddTask(
				new HttpTextAsyncTask(item).SetRequestType(HttpRequestType),
				new OnHttpRequestTextListener() {

					@Override
					public void OnFail(boolean arg0, String arg1) {
						if (requestResultListener != null) {
							requestResultListener.onResult(null, arg0, arg1);
						}
					}

					@Override
					public void OnProgress(long arg0, long arg1) {
					}

					@Override
					public void OnSuccess(HttpInvokeItem arg0, boolean arg1,
							String arg2) {
						requestResultListener.onResult(arg0, arg1, "");
					}
				});
	}

}
